//Component Object
const app = getApp();
const { apiInstance } = app

Component({
  properties: {
    data: {
      type: Object,
      value: {},
      observer: function (e) {
        if (e) {

          this.setData({
            form: e.shenBao,
            occupationalHealthTypeCurrent:e.shenBao?.occupationalHealthType||[],
          })
        }
      }
    },
    isEdit: {
      type: Boolean,
      value: false,
      observer: function (e) {
        if (e) {
          this.setData({
            isEdit: e,
          })
        }
      }
    },
  },
  data: {
    form: {
      hazardousChemicals:''
    },
    isEdit:false,
    occupationalHealthTypeCurrent: [],
    safeEquipmentCurrent:'',
    includeSpecialEquipmentCurrent:'',
    buildingUseageCurrent: '',
    facilityRenovationCurrent:'',
    occupationalHealthTypeList: [{
      id: 1,
      name: '布局规划',
    }, {
      id: 2,
      name: '建筑设计'
    }, {
      id: 3,
      name: '生产工艺/设备说明'
    },
    {
      id: 4,
      name: '安全文明施工措施方案'
    },
    {
      id: 5,
      name: '《工程项目安全环保承诺书》'
    }
    
  ],
  safeEquipmentList: [{
    id: 1,
    name: '不需要'
  }, {
    id: 2,
    name: '需要'
  }],
  isOrNotList:[{
    id:1,
    name:'是'
  },{
    id:2,
    name:'否'
  }],
  facilityRenovationHeaders:[{
    label:'危化品名称',
    value:'word1'
  },
  {
    label:'主要成分',
    value:'word2'
  },
  {
    label:'危害',
    value:'word3'
  },
  {
    label:'用途',
    value:'word4'
  },
  {
    label:'存放/使用量(Kg)',
    value:'word5'
  }
  ],
  facilityRenovationData:[{
    word1:'',
    word2:'',
    word3:'',
    word4:'',
    word5:''
  }]

  },
  methods: {
    handleOccupationalHealthTypeChange({detail}) {
      this.data.occupationalHealthTypeCurrent??=[];
      const index = this.data.occupationalHealthTypeCurrent?.indexOf(detail.value);
      (index == -1||index=='undefined') ? this.data.occupationalHealthTypeCurrent.push(detail.value) : this.data.occupationalHealthTypeCurrent.splice(index, 1);
      this.setData({
        occupationalHealthTypeCurrent: this.data.occupationalHealthTypeCurrent,
        'form.occupationalHealthType': this.data.occupationalHealthTypeCurrent
      });
    },

    handleIncludeSpecialEquipmentChange({detail}) {
     this.setData({
        includeSpecialEquipmentCurrent: detail.value,
        'form.includeSpecialEquipment': detail.value
      });
    },

    handleBuildingUseageListChange({detail}) {
      this.setData({
        safeEquipmentCurrent: detail.value,
         'form.safeEquipment': detail.value
       });
     },
     bindValue(e){
      console.log(111,this.selectComponent("#hazardousChemicalsTable")?.data);
      this.setData({
        [e.target.dataset.itemname]:e.detail.detail.value,
      });

      console.log('e',e);
    },

     handleFacilityRenovationChange({ detail }) {

      this.setData({
        hazardousChemicalsCurrent: detail.value,
        'form.hazardousChemicals': detail.value,
        'form.hazardousChemicalstableData':this.selectComponent("#hazardousChemicalsTable")?.data.data
      });
    },

    getForm(){
      return Object.assign({},this.data.form, 
        (this.data.form?.hazardousChemicals=='是'?{hazardousChemicalstableData:this.selectComponent("#hazardousChemicalsTable")?.data.data}:{})
        )

    },
   
  },
  lifetimes: {
    created: async function () {

    },
    attached: function () {

    },
    ready: async function () {


    },
    moved: function () {

    },
    detached: function () {

    }
  }

});